﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.Domain.Values
{
	using System;
	using System.Web.Mvc;
	using Falcon.Core.Domain.Enums;
	using Falcon.Core.Domain.Services;
	using Falcon.Core.Extensions;

	public class UserPreferenceUpdate : ValueBase<UserPreferenceUpdate>
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="UserPreferenceUpdate"/> class.
		/// </summary>
		public UserPreferenceUpdate()
		{
			this.CountryService = Application.Resolve<ICountryService>();
			this.TimeZoneService = Application.Resolve<ITimeZoneService>();
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="UserPreferenceUpdate"/> class.
		/// </summary>
		/// <param name="preference">The preference.</param>
		public UserPreferenceUpdate(UserPreference preference) 
			: this(0, preference)
		{

		}

		/// <summary>
		/// Initializes a new instance of the <see cref="UserPreferenceUpdate"/> class.
		/// </summary>
		/// <param name="userId">The user id.</param>
		/// <param name="preference">The preference.</param>
		public UserPreferenceUpdate(int userId, UserPreference preference) : this()
		{
			this.UserId = userId;
			this.CountryId = preference.CountryId;
			this.TimeZoneId = preference.TimeZoneId;
			this.IsMessagingEnabled = preference.IsMessagingEnabled;
			this.IsMessagingRetrictedEnabled = preference.IsMessagingRetrictedEnabled;
			this.IsMessagingNotificationEnabled = preference.IsMessagingNotificationEnabled;
			this.IsProfileMessagingEnabled = preference.IsProfileMessagingEnabled;
			this.IsProfileMessagingRetrictedEnabled = preference.IsProfileMessagingRetrictedEnabled;
			this.IsProfileMessagingNotificationEnabled = preference.IsProfileMessagingNotificationEnabled;
			this.IsFriendshipNotificationEnabled = preference.IsFriendshipNotificationEnabled;
			this.Dst = preference.Dst;
			this.StartOfWeek = preference.StartOfWeek;
			this.TimeFormat = preference.TimeFormat;
		}

		/// <summary>
		/// Gets or sets the country repository.
		/// </summary>
		/// <value>The country repository.</value>
		public ICountryService CountryService
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets or sets the time zone repository.
		/// </summary>
		/// <value>The time zone repository.</value>
		public ITimeZoneService TimeZoneService
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets or sets the user id.
		/// </summary>
		/// <value>The user id.</value>
		public int UserId
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the country id.
		/// </summary>
		/// <value>The country id.</value>
		public int CountryId
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the time zone id.
		/// </summary>
		/// <value>The time zone id.</value>
		public int TimeZoneId
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is messaging enabled.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is messaging enabled; otherwise, <c>false</c>.
		/// </value>
		public bool IsMessagingEnabled
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is messaging retricted enabled.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is messaging retricted enabled; otherwise, <c>false</c>.
		/// </value>
		public bool IsMessagingRetrictedEnabled
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is messaging notification enabled.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is messaging notification enabled; otherwise, <c>false</c>.
		/// </value>
		public bool IsMessagingNotificationEnabled
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is profile messaging enabled.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is profile messaging enabled; otherwise, <c>false</c>.
		/// </value>
		public bool IsProfileMessagingEnabled
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is profile messaging retricted enabled.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is profile messaging retricted enabled; otherwise, <c>false</c>.
		/// </value>
		public bool IsProfileMessagingRetrictedEnabled
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is profile messaging notification enabled.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is profile messaging notification enabled; otherwise, <c>false</c>.
		/// </value>
		public bool IsProfileMessagingNotificationEnabled
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether this instance is friendship notification enabled.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is friendship notification enabled; otherwise, <c>false</c>.
		/// </value>
		public bool IsFriendshipNotificationEnabled
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the DST.
		/// </summary>
		/// <value>The DST.</value>
		public UserPreferenceDaylightSavingTime Dst
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the start of week.
		/// </summary>
		/// <value>The start of week.</value>
		public UserPreferenceStartOfWeek StartOfWeek
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the time format.
		/// </summary>
		/// <value>The time format.</value>
		public UserPreferenceTimeFormat TimeFormat
		{
			get;
			set;
		}

		/// <summary>
		/// Gets the countries.
		/// </summary>
		/// <value>The countries.</value>
		public SelectList Countries
		{
			get
			{
				return new SelectList(this.CountryService.GetAll(), "Id", "Title", this.CountryId);
			}
		}

		/// <summary>
		/// Gets the time zones.
		/// </summary>
		/// <value>The time zones.</value>
		public SelectList TimeZones
		{
			get
			{
				return new SelectList(this.TimeZoneService.GetAll(), "Id", "Display", this.TimeZoneId);
			}
		}

		/// <summary>
		/// Gets the DSTS.
		/// </summary>
		/// <value>The DSTS.</value>
		public SelectList Dsts
		{
			get
			{
				return new SelectList(Enum.GetNames(typeof(UserPreferenceDaylightSavingTime)), this.Dst.Name());
			}
		}

		/// <summary>
		/// Gets the start of weeks.
		/// </summary>
		/// <value>The start of weeks.</value>
		public SelectList StartOfWeeks
		{
			get
			{
				return new SelectList(Enum.GetNames(typeof(UserPreferenceStartOfWeek)), this.StartOfWeek.Name());
			}
		}

		/// <summary>
		/// Gets the time formats.
		/// </summary>
		/// <value>The time formats.</value>
		public SelectList TimeFormats
		{
			get
			{
				return new SelectList(Enum.GetNames(typeof(UserPreferenceTimeFormat)), this.TimeFormat.Name());
			}
		}

		/// <summary>
		/// Validates this instance.
		/// </summary>
		public override void Validate()
		{
			this.Rules().Validate(this);
		}
	}
}